package br.com.vemtransporte;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class EmailValidationActivity extends Activity{
	
	EditText edtTxtNome, edtTxtEmail, edtTxtData, edtTxtSenha;
	String strEmailAddress;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        edtTxtEmail = (EditText) findViewById(R.id.editTextEmail);
    }

    String regEx =
    	"^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
    	    +"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
    	    +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
    	    +"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
    	    +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
    	    +"([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";

    public void btnValidateEmailAddress(View v)
    {
    	strEmailAddress = edtTxtEmail.getText().toString().trim();

        Matcher matcherObj = Pattern.compile(regEx).matcher(strEmailAddress);

        if (matcherObj.matches())
        {
        	Toast.makeText(v.getContext(), strEmailAddress+" is valid", Toast.LENGTH_SHORT).show();
        }
        else
        {
        	Toast.makeText(v.getContext(), strEmailAddress+" is InValid", Toast.LENGTH_SHORT).show();
        }
    }
}